What is @babel/plugin-syntax-logical-assignment-operators?
The @babel/plugin-syntax-logical-assignment-operators package allows Babel to parse code that uses logical assignment operators. These operators combine logical operations with assignment expressions. This plugin only enables the syntax, and does not transform it. To transform the code, you would need to use another plugin or set of plugins that handle the transformation.
What are @babel/plugin-syntax-logical-assignment-operators's main functionalities?
Logical AND Assignment (&&=)
The logical AND assignment (&&=) operator only assigns the value of the right operand to the left operand if the left operand is truthy.
a &&= b;
Logical OR Assignment (||=)
The logical OR assignment (||=) operator assigns the value of the right operand to the left operand if the left operand is falsy.
a ||= b;
Logical Nullish Assignment (??=)
The logical nullish assignment (??=) operator assigns the value of the right operand to the left operand if the left operand is null or undefined.
a ??= b;
Other packages similar to @babel/plugin-syntax-logical-assignment-operators
@babel/plugin-proposal-logical-assignment-operators
This package is a proposal plugin that not only allows Babel to parse logical assignment operators but also transforms them. It is similar to @babel/plugin-syntax-logical-assignment-operators but includes the transformation step.
@babel/preset-env
While not exclusively focused on logical assignment operators, @babel/preset-env includes the necessary plugins to both parse and transform modern JavaScript syntax, including logical assignment operators, based on the target environment.
@babel/plugin-syntax-logical-assignment-operators
Allow parsing of the logical assignment operators
See our website @babel/plugin-syntax-logical-assignment-operators for more information.
Install
Using npm:
npm install --save-dev @babel/plugin-syntax-logical-assignment-operators
or using yarn:
yarn add @babel/plugin-syntax-logical-assignment-operators --dev